package com.example.gulimall.search.controller;

import com.example.gulimall.search.service.SearchService;
import com.example.gulimall.search.vo.SearchParam;
import com.netflix.client.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import com.example.gulimall.search.vo.SearchResult;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;


@Controller
public class SearchController {
    @Autowired
    SearchService searchService;
    @GetMapping({"/list.html","/"})
    public String getSearchPage(SearchParam param, Model model, HttpServletRequest httpServletRequest){
        String queryString = httpServletRequest.getQueryString();
        param.set_queryString(queryString);
        SearchResult result=searchService.getSearchResult(param);
        model.addAttribute("result",result);
        return "list";
    }
}
